package com.hkts.management.unattended.weightingInfo.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.unattended.master.service.MasterService;
import com.hkts.management.unattended.order.entity.HktsOrderInfo;
import com.hkts.management.unattended.order.service.IHktsOrderInfoService;
import com.hkts.management.unattended.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.unattended.weightingInfo.service.IWeightingInfoService;
import com.hkts.management.unattended.weightingInfo.entity.WeightingInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zy
 * @since 2021-09-17
 */
@RestController
@RequestMapping("/order/weightingInfo")
public class WeightingInfoController {
    private final Logger logger = LoggerFactory.getLogger(WeightingInfoController.class);

    @Autowired
    public IWeightingInfoService iWeightingInfoService;
    @Autowired
    private IHktsOrderInfoService orderInfoService;
    @Autowired
    private MasterService masterService;

    /**
     * 分页查询数据
     *
     * @param page          分页信息
     * @param weightingInfo 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getWeightingInfoPageList")
    public Result<Object> getWeightingInfoPageList(Page<WeightingInfo> page, WeightingInfo weightingInfo) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iWeightingInfoService.selectPage(page, weightingInfo)));
    }

    /**
     * 保存和修改公用的
     *
     * @param weightingInfo 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/weightingInfoSave")
    public Result<Object> weightingInfoSave(WeightingInfo weightingInfo) {
        iWeightingInfoService.saveOrUpdate(weightingInfo);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/weightingInfoGetById")
    public Result<Object> weightingInfoGetById(String id) {
        WeightingInfo byId = iWeightingInfoService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/weightingInfoDelete")
    public Result<Object> hontUserDelete(String id) {
        iWeightingInfoService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/weightingInfoBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iWeightingInfoService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    @ResponseBody
    @GetMapping("/getList")
    public Result<Object> getList() {
        Map<String, Object> ms=new HashMap<>();
        List<WeightingInfo> s=iWeightingInfoService.selectList();
        List<HktsOrderInfo> ss=orderInfoService.selectList();
        ms.put("s",s);
        ms.put("ss",ss);
        return ResultUtil.data(ms);
    }
    @ResponseBody
    @GetMapping("/saveList")
    public Result<Object> saveList() {
        masterService.select();
        return ResultUtil.success();
    }
}
